package com.jboost.modules.system.mapper;

import java.util.List;

import com.jboost.modules.system.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.jboost.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id in (select id from sys_user where username=#{username})) order by id")
	List<String> getRoleByUserName(@Param("username") String username);
	@Select("<script> select role_code from sys_role where id in (select role_id from sys_user_role where user_id = #{userId} ) <if test='null!=domain'>and domain = #{domain}</if> order by id </script>")
	List<String> getRoleByUserId(@Param("userId") String userId ,String domain);

	@Select("select role_name from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where id=#{id})) order by create_time")
	List<String> getRoleNameByUserId(@Param("id") String id);

	@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleIdByUserName(@Param("username") String username);
	@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id in (select id from sys_user where id in \n" +
			"(select user_id from sys_user_account sua where account_id = '1397115444493574145') ))")
	List<String> getRoleIdByAccountId(@Param("accountId") String accountId);

	@Select("select su.* from `sys_user` su ,`sys_user_role` sur where sur.role_id = #{roleId} and su.id = sur.`user_id`")
    List<SysUser> getUserByRoleId(String roleId);
}
